/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-29 13:35:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { FormInstance, Modal } from 'antd';
import HeaderForm from '@/components/form';

import React from 'react';
import { EVipLevel, SEX, VipLevelList } from '@/enum';
import { edit_user, add_user } from '../../../services/pages';
import moment from 'moment';
interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const VipModal = (props: IProps) => {
  const List = [
    {
      key: 'user_name',
      type: IFormTypeEnum.Input,
      label: '姓名',
      rules: [{ required: true }],
    },
    {
      key: 'sex',
      type: IFormTypeEnum.RadioGroup,
      label: '性别',
      data: {
        list: SEX,
      },
      rules: [{ required: true }],
    },
    {
      key: 'mobile',
      type: IFormTypeEnum.InputNumber,
      label: '手机号码',
      rules: [{ required: true }],
    },
    {
      key: 'birthday',
      type: IFormTypeEnum.DatePicker,
      label: '出生日期',
      rules: [{ required: true }],
    },
    // {
    //   key: 'vip_level',
    //   type: IFormTypeEnum.Select,
    //   data: {
    //     list: VipLevelList,
    //   },
    //   initValue: VipLevelList[0].value,
    //   label: '会员等级',
    //   rules: [{ required: true }],
    // },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    values.birthday = moment(values.birthday).unix();
    if (props.row?.user_id) {
      await edit_user({ ...values, user_id: props.row?.user_id });
    } else {
      await add_user(values);
    }
    props.close();
    props.refresh();
  };

  return (
    <Modal
      maskClosable={false}
      visible={props.visible}
      title={props.row?.user_id ? '编辑会员' : '添加会员'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={80}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={{
          ...props.row,
          birthday: props.row?.user_id
            ? moment(Number(props.row?.birthday) * 1000)
            : null,
        }}
      />
    </Modal>
  );
};
export default VipModal;
